﻿using System;
using System.Diagnostics;

namespace Sustainalytics.Common.Hosting
{
    public interface IBasicLogger
    {
        void Log(EventLogEntryType level, string message);
    }

    public class BasicConsoleLogger : IBasicLogger
    {
        public void Log(EventLogEntryType level, string message)
        {
            var previousConsoleColor = Console.ForegroundColor;

            try
            {
                switch (level)
                {
                    case EventLogEntryType.Error:
                        Console.ForegroundColor = ConsoleColor.Red;
                        break;
                    default :
                        break;
                }
                Console.WriteLine("[{0}] {1}", level, message);
            }
            finally
            {
                Console.ForegroundColor = previousConsoleColor;
            }
        }
    }
    public class BasicEventLogLogger : IBasicLogger
    {
        string source;
        public BasicEventLogLogger(string  source)
        {
            this.source = source;
        }
        public void Log(EventLogEntryType level, string message)
        {
            if (string.IsNullOrEmpty(source))
                return;
            
            EventLog.WriteEntry(source, message, level);
        }
    }
}
